﻿package mortal.game.view.copy.wine.view
{
    import Message.Public.*;
    import com.gengine.global.*;
    import com.gengine.utils.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import extend.language.*;
    import fl.data.*;
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.game.cache.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.scene3D.map3D.*;
    import mortal.game.view.common.*;
    import mortal.game.view.copy.guildCopy.*;
    import mortal.game.view.copy.wine.data.*;
    import mortal.game.view.copy.wine.renderer.*;
    import mortal.game.view.vip.*;
    import mortal.game.view.vip.panel.*;
    import mortal.mvc.core.*;

    public class WinePartyDetailWin extends View
    {
        private var _bodySpr:GSprite;
        private var _currJionPersonNum:GTextFiled;
        private var _rewardAddPercent:GTextFiled;
        private var _currGainExp:GTextFiled;
        private var _currGainPraise:GTextFiled;
        private var _rankList:GTileList;
        private var _myRankLink:GTextFiled;
        private var _myRank:GTextFiled;
        private var _moveBtn:GLoadedButton;
        private var _btnShowTrack:GuildCopyHurtListShowAndHide;
        private var _leftTime:SecTimerView;
        private var _vipOpenTips1:VipOpenTipsPanel;
        private var _vipOpenTips2:VipOpenTipsPanel;
        private var _expAddition:GTextFiled;
        private var _donateAddition:GTextFiled;
        private var _isCreateChildren:Boolean;
        private var _dragRect:Rectangle;
        private static var _instance:WinePartyDetailWin;

        public function WinePartyDetailWin()
        {
            this.layer = LayerManager.uiLayer;
            this.mouseEnabled = false;
            if (_instance)
            {
                throw new Error("WineDetailWin 单例");
            }
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.createChildren();
            return;
        }// end function

        private function createChildren() : void
        {
            this._isCreateChildren = true;
            this._bodySpr = UICompomentPool.getUICompoment(GSprite);
            this.addChild(this._bodySpr);
            this.pushUIToDisposeVec(UIFactory.bg(0, 0, 251 + 10 + 6, 457, this._bodySpr, ImagesConst.WineDetailBg));
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.Text_PersonNumRank, 50 + 35, 100 + 60 + 77, this._bodySpr));
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(40987), 52, 10, 90, 22, this._bodySpr, GlobalStyle.textFormatHuang2.setSize(13)));
            this._leftTime = UIFactory.secTimeView(Language.getString(40988), 52 + 79, 10, 70, 22, this._bodySpr, GlobalStyle.textFormatHong.setSize(13));
            var _loc_1:* = GlobalStyle.textFormatHuang2;
            _loc_1.size = 14;
            this._currJionPersonNum = UIFactory.gTextField(Language.getString(40989), 18 - 12 + 6, 43, 200, 25, this._bodySpr, _loc_1);
            this._rewardAddPercent = UIFactory.gTextField(Language.getString(40990), 18 - 12 + 6, 43 + 36, 200, 25, this._bodySpr, _loc_1);
            this._currGainExp = UIFactory.gTextField(Language.getString(40991), 18 - 12 + 6, 43 + 36 * 2, 200, 25, this._bodySpr, _loc_1);
            this._currGainPraise = UIFactory.gTextField(Language.getString(40992), 18 - 12 + 6, 43 + 36 * 3, 200, 30, this._bodySpr, _loc_1);
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(40993), 30, 185 - 3 + 77, 38, 20, this._bodySpr, GlobalStyle.textFormatBai));
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(40994), 103, 185 - 3 + 77, 38, 20, this._bodySpr, GlobalStyle.textFormatBai));
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(40995), 181, 185 - 3 + 77, 62, 20, this._bodySpr, GlobalStyle.textFormatBai));
            this._rankList = UIFactory.tileList(11, 203 + 77, 232, 287, this._bodySpr);
            this._rankList.columnWidth = 231;
            this._rankList.rowHeight = 28;
            this._rankList.horizontalGap = 0;
            this._rankList.verticalGap = 0;
            this._rankList.setStyle("skin", new Bitmap());
            this._rankList.setStyle("cellRenderer", WinePartyDetailRankCellRenderer);
            var _loc_2:* = GlobalStyle.textFormatLv;
            _loc_2.size = 14;
            this._myRankLink = UIFactory.gTextField(Language.getString(40996), 81, 504 - 4 - 160 + 77, 76, 25, this._bodySpr, _loc_2);
            this._myRank = UIFactory.gTextField("", 153, 504 - 3 - 160 + 77, 45, 25, this._bodySpr, _loc_2);
            this._moveBtn = UIFactory.gLoadedButton(ImagesConst.TaskTrackMove_upSkin, 2, 23 - 10, 18, 18, this._bodySpr);
            this._moveBtn.toolTipData = HTMLUtil.addColor(Language.getString(20143), "#FFFFFF");
            this._moveBtn.configEventListener(MouseEvent.MOUSE_DOWN, this.onMoveHandler);
            this._btnShowTrack = UICompomentPool.getUICompoment(GuildCopyHurtListShowAndHide);
            this._btnShowTrack.width = 18;
            this._btnShowTrack.height = 18;
            this._btnShowTrack.x = 210 + 17 + 10 + 9;
            this._btnShowTrack.y = 23 - 10;
            this.addChild(this._btnShowTrack);
            this._btnShowTrack.configEventListener(MouseEvent.CLICK, this.onClickHide);
            this._dragRect = new Rectangle();
            this._dragRect.x = 0;
            this._dragRect.y = 0;
            this._dragRect.width = SceneRange.display.width - 30;
            this._dragRect.height = SceneRange.display.height - 30;
            this._vipOpenTips1 = UICompomentPool.getUICompoment(VipOpenTipsPanel);
            this._vipOpenTips1.valueType = VipOpenTipsPanel.percentValue;
            this._vipOpenTips1.resetLevelTextPos(73 - 39 + 23, 1, 73 - 39, 1);
            this._vipOpenTips1.resetValueTextPos(96 + 17 + 43, 1, 96 + 17, 1);
            this._vipOpenTips1.move(18 - 10 + 3, 116 + 20);
            this._bodySpr.addChild(this._vipOpenTips1);
            this._vipOpenTips1.bgUrl = "";
            this._vipOpenTips1.resetTipsTextPos(0, 0, 0, 0);
            this._vipOpenTips1.vipType = EVipRecordType._EVipRecordTypeWineExp;
            this._vipOpenTips2 = UICompomentPool.getUICompoment(VipOpenTipsPanel);
            this._vipOpenTips2.valueType = VipOpenTipsPanel.percentValue;
            var _loc_3:* = Cache.instance.vip.level;
            var _loc_4:* = VipUtil.getVipMinLevelByType(EVipRecordType._EVipRecordTypeWineExp);
            if (_loc_3 < _loc_4)
            {
                this._vipOpenTips2.resetLevelTextPos(73 - 39 + 23, 3, 73 - 39 + 23, 3);
                this._vipOpenTips2.resetValueTextPos(96 + 17 + 43, 3, 96 + 17 + 43, 3);
            }
            else
            {
                this._vipOpenTips2.resetLevelTextPos(73 - 39 + 23, 1, 73 - 39, 1);
                this._vipOpenTips2.resetValueTextPos(96 + 17 + 43, 1, 96 + 17, 1);
            }
            this._vipOpenTips2.move(18 - 10 + 3, 152 + 20);
            this._bodySpr.addChild(this._vipOpenTips2);
            this._vipOpenTips2.bgUrl = "";
            this._vipOpenTips2.resetTipsTextPos(0, 0, 0, 0);
            this._vipOpenTips2.vipType = 420;
            this._expAddition = UIFactory.gTextField("", 124 + 20 - 11 + 8, 116 + 20 - 4 + 2, 126, 25, this._bodySpr, GlobalStyle.textFormatLv.setSize(13));
            this._donateAddition = UIFactory.gTextField("", 124 + 20 - 11 + 8, 152 + 20 - 4 + 2, 126, 25, this._bodySpr, GlobalStyle.textFormatLv.setSize(13));
            this.stageResize();
            this.addListeners();
            return;
        }// end function

        private function addListeners() : void
        {
            NetDispatcher.addCmdListener(ServerCommand.WinePartyDetailRankUpdate, this.onRankInfoUpdate);
            return;
        }// end function

        private function removeListeners() : void
        {
            NetDispatcher.removeCmdListener(ServerCommand.WinePartyDetailRankUpdate, this.onRankInfoUpdate);
            return;
        }// end function

        override public function show(param1:int = 0, param2:int = 0) : void
        {
            super.show();
            this.stageResize();
            return;
        }// end function

        override public function stageResize() : void
        {
            super.stageResize();
            this.x = Global.stage.stageWidth - 50 - 238;
            this.y = 130 + 18;
            return;
        }// end function

        private function initRankList() : void
        {
            var _loc_4:WineDetailRankData = null;
            var _loc_1:Array = [];
            var _loc_2:int = 1;
            while (_loc_2 <= 5)
            {
                
                _loc_4 = new WineDetailRankData();
                _loc_4.rank = _loc_2;
                _loc_4.roleName = "玩家名字七个字";
                _loc_4.fuddleNum = 99999;
                _loc_1.push(_loc_4);
                _loc_2++;
            }
            var _loc_3:* = new DataProvider();
            _loc_3.addItems(_loc_1);
            this._rankList.dataProvider = _loc_3;
            this._rankList.drawNow();
            return;
        }// end function

        private function onRankInfoUpdate(param1:Object) : void
        {
            var _loc_9:int = 0;
            var _loc_10:Number = NaN;
            var _loc_11:SGuildWinePartyDrunkInfo = null;
            var _loc_12:WineDetailRankData = null;
            var _loc_2:* = Cache.instance.copy.wineParty.winePartyDetailInfo;
            this._currJionPersonNum.text = Language.getStringByParam(40989, _loc_2.num);
            this._rewardAddPercent.text = Language.getStringByParam(40990, _loc_2.percent);
            this._currGainExp.text = Language.getStringByParam(40991, _loc_2.exp);
            this._currGainPraise.text = Language.getStringByParam(40992, _loc_2.contribution);
            var _loc_3:* = Cache.instance.vip.level;
            var _loc_4:* = VipUtil.getVipMinLevelByType(EVipRecordType._EVipRecordTypeWineExp);
            if (_loc_3 < _loc_4)
            {
                this._expAddition.text = "";
                this._donateAddition.text = "";
            }
            else
            {
                _loc_9 = int(VipConfig.instance.getValueByTypeAndLv(EVipRecordType._EVipRecordTypeWineExp, _loc_3));
                _loc_10 = _loc_9 / (100 + _loc_9);
                this._expAddition.text = Language.getStringByParam(40997, int(_loc_2.exp * _loc_10));
                this._donateAddition.text = Language.getStringByParam(40997, int(_loc_2.contribution * _loc_10));
            }
            var _loc_5:* = Cache.instance.role.entityInfo.name;
            var _loc_6:Array = [];
            var _loc_7:int = 0;
            while (_loc_7 < _loc_2.rankInfo.length)
            {
                
                _loc_11 = _loc_2.rankInfo[_loc_7];
                if (_loc_7 < 5)
                {
                    _loc_12 = new WineDetailRankData();
                    _loc_12.rank = _loc_11.rank;
                    _loc_12.roleName = _loc_11.playerName;
                    _loc_12.fuddleNum = _loc_11.drunkTimes;
                    _loc_6.push(_loc_12);
                }
                if (_loc_11.playerName == _loc_5)
                {
                    this._myRank.text = _loc_11.rank + "";
                    if (_loc_7 > 5)
                    {
                        break;
                    }
                }
                _loc_7++;
            }
            this.updateLeftTime();
            var _loc_8:* = new DataProvider();
            _loc_8.addItems(_loc_6);
            this._rankList.dataProvider = _loc_8;
            this._rankList.drawNow();
            return;
        }// end function

        private function onClickHide(event:MouseEvent) : void
        {
            this._bodySpr.visible = !this._bodySpr.visible;
            return;
        }// end function

        private function onMoveHandler(event:MouseEvent) : void
        {
            startDrag(false, this._dragRect);
            Global.stage.addEventListener(MouseEvent.MOUSE_UP, this.onStageMouseUpHandler);
            return;
        }// end function

        private function onStageMouseUpHandler(event:MouseEvent) : void
        {
            stopDrag();
            Global.stage.removeEventListener(MouseEvent.MOUSE_UP, this.onStageMouseUpHandler);
            return;
        }// end function

        private function updateLeftTime() : void
        {
            var _loc_2:SGuildWinePartyDrunkInfo = null;
            var _loc_1:* = Cache.instance.copy.wineParty.winePartyDetailInfo;
            if (_loc_1)
            {
                for each (_loc_2 in _loc_1.rankInfo)
                {
                    
                    if (_loc_2.playerName == Cache.instance.role.entityInfo.name)
                    {
                        this._leftTime.setLeftTime(_loc_2.surplusSeconds);
                        break;
                    }
                }
            }
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl();
            if (this._isCreateChildren)
            {
                this._isCreateChildren = false;
                this._currJionPersonNum.dispose();
                this._rewardAddPercent.dispose();
                this._currGainExp.dispose();
                this._currGainPraise.dispose();
                this._rankList.dispose();
                this._myRank.dispose();
                this._myRankLink.dispose();
                this._bodySpr.dispose();
                this._moveBtn.dispose();
                this._leftTime.dispose();
                this._vipOpenTips1.dispose();
                this._vipOpenTips2.dispose();
                this._expAddition.dispose();
                this._donateAddition.dispose();
                this._currJionPersonNum = null;
                this._rewardAddPercent = null;
                this._currGainExp = null;
                this._currGainPraise = null;
                this._rankList = null;
                this._myRankLink = null;
                this._myRank = null;
                this._bodySpr = null;
                this._dragRect = null;
                this._moveBtn = null;
                this._leftTime = null;
                this._vipOpenTips1 = null;
                this._vipOpenTips2 = null;
                this._expAddition = null;
                this._donateAddition = null;
            }
            this.removeListeners();
            return;
        }// end function

        public static function get instance() : WinePartyDetailWin
        {
            if (_instance == null)
            {
                _instance = new WinePartyDetailWin;
            }
            return _instance;
        }// end function

    }
}
